package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SearchResult;
import com.ruoyi.system.service.ISearchResultService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检索结果Controller
 * 
 * @author ruoyi
 * @date 2024-08-22
 */
@Controller
@RequestMapping("/system/searchResult")
public class SearchResultController extends BaseController
{
    private String prefix = "system/searchResult";

    @Autowired
    private ISearchResultService searchResultService;

    @RequiresPermissions("system:searchResult:view")
    @GetMapping()
    public String searchResult()
    {
        return prefix + "/searchResult";
    }

    /**
     * 查询检索结果列表
     */
    @RequiresPermissions("system:searchResult:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SearchResult searchResult)
    {
        startPage();
        List<SearchResult> list = searchResultService.selectSearchResultList(searchResult);
        return getDataTable(list);
    }

    /**
     * 导出检索结果列表
     */
    @RequiresPermissions("system:searchResult:export")
    @Log(title = "检索结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SearchResult searchResult)
    {
        List<SearchResult> list = searchResultService.selectSearchResultList(searchResult);
        ExcelUtil<SearchResult> util = new ExcelUtil<SearchResult>(SearchResult.class);
        return util.exportExcel(list, "检索结果数据");
    }

    /**
     * 新增检索结果
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存检索结果
     */
    @RequiresPermissions("system:searchResult:add")
    @Log(title = "检索结果", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SearchResult searchResult)
    {
        return toAjax(searchResultService.insertSearchResult(searchResult));
    }

    /**
     * 修改检索结果
     */
    @RequiresPermissions("system:searchResult:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SearchResult searchResult = searchResultService.selectSearchResultById(id);
        mmap.put("searchResult", searchResult);
        return prefix + "/edit";
    }

    /**
     * 修改保存检索结果
     */
    @RequiresPermissions("system:searchResult:edit")
    @Log(title = "检索结果", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SearchResult searchResult)
    {
        return toAjax(searchResultService.updateSearchResult(searchResult));
    }

    /**
     * 删除检索结果
     */
    @RequiresPermissions("system:searchResult:remove")
    @Log(title = "检索结果", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(searchResultService.deleteSearchResultByIds(ids));
    }

    /**
     * 全库检索
     */
    @RequiresPermissions("system:searchResult:remove")
    @Log(title = "检索结果", businessType = BusinessType.OTHER)
    @PostMapping( "/fullSearch")
    @ResponseBody
    public AjaxResult fullSearch(){
        return toAjax(searchResultService.fullSearch());
    }
}
